;; (init-load-path  "~/.stumpwm.d/modules")
(set-font "-*-fixed-medium-r-*-*-10-*-*-*-*-*-*")
(define-key *root-map* (kbd "?") "")
(run-shell-command "./.fehbg")

;;; modules
;; (load "~/quicklisp/setup.lisp")
;; (load-module "mem")
;; (ql:quickload "cl-diskspace")
;; (load-module "disk")
;; (setf disk:*disk-usage-paths* '("/" "/media" "/mnt")
;;       disk:*disk-modeline-fmt* "%m: %p")
;; (load-module "mpd")
;; (mpd:mpd-connect)
;; (setf mpd:*mpd-status-fmt* "%S"
;;       mpd:*mpd-modeline-fmt* "%a - %T. %t [%L %e]")
;; (define-key *root-map* (kbd "m") mpd:*mpd-map*)
;; (define-key *top-map* (kbd "C-F1") "mpd-volume-down")
;; (define-key *top-map* (kbd "C-F2") "mpd-volume-up")

;;; variables
(defvar *browser* "qutebrowser")
(defvar *file-manager* "xfe")
(defvar *terminal* "urxvt")

;;; mode-line
(setf *window-format* "%m%n%s%c"
      *time-modeline-string* "%m/%e %k:%M"
      *screen-mode-line-format* (list "[%d] [%n] %W")
      *mode-line-foreground-color* "#FFFFFF"
      *mode-line-background-color* "#000000"
      *mode-line-border-color* "#000000"
      *mode-line-position* :top
      *mode-line-pad-x* 5
      *mode-line-pad-y* 1
      *mode-line-border-width* 0
      *mode-line-timeout* 1)
(define-key *root-map* (kbd "SPC") "mode-line")

;;; message/input bar
(setf *message-window-gravity* :center
      *input-window-gravity* :center
      *timeout-wait* 4)

;;; groups
(grename "I")
(gnewbg "II")
(gnewbg-float "III")

;;; frames and windows
(define-key *root-map* (kbd "C-o") "fprev")
(define-key *root-map* (kbd "TAB") "fother")
(define-key *root-map* (kbd "C-f") "float-this")
(define-key *root-map* (kbd "M-f") "flatten-floats")
(setf *window-border-style* :thin
      *ignore-wm-inc-hints* T
      *normal-border-width* 1
      *mouse-focus-policy* :click
      *float-window-modifier* :SUPER)
(set-focus-color "#FFFFFF")
(set-unfocus-color "#000000")
(set-win-bg-color "#000000")
(set-float-focus-color "blue")
(set-float-unfocus-color "#000000")

;;; programs, the macro was taken from the mpd.lisp module
(defmacro fill-keymap (map &rest bindings)
  `(unless ,map
     (setf ,map
           (let ((m (make-sparse-keymap)))
             ,@(loop for i = bindings then (cddr i)
                     while i
                     collect `(define-key m ,(first i) ,(second i)))
             m))))

(defcommand emacs () ()
  (run-or-raise "emacs" `(:instance "emacs")))
(defcommand browser () ()
  (run-or-raise *browser* `(:instance ,*browser*)))
(defcommand fm () ()
  (run-or-raise *file-manager* `(:instance ,*file-manager*)))
(defcommand term () ()
  (run-or-raise *terminal* `(:instance ,*terminal*)))
(defcommand discord () ()
  (run-or-raise "disc" `(:instance "discord")))
(defcommand raise-mpv () ()
  (run-or-raise "" '(:title "mpv")))

(defcommand pull-emacs () ()
  (run-or-pull "emacs" `(:instance "emacs")))
(defcommand pull-browser () ()
  (run-or-pull *browser* `(:instance ,*browser*)))
(defcommand pull-fm () ()
  (run-or-pull *file-manager* `(:instance ,*file-manager*)))
(defcommand pull-term () ()
  (run-or-pull *terminal* `(:instance ,*terminal*)))
(defcommand pull-discord () ()
  (run-or-pull "disc" `(:instance "discord")))
(defcommand pull-mpv () ()
  (run-or-pull "" '(:title "mpv")))

(defvar *programs-keymap* NIL)

(fill-keymap *programs-keymap*
	     (kbd "e") "emacs"
	     (kbd "C-e") "pull-emacs"
	     (kbd "M-e") "exec emacs"
	     (kbd "b") "browser"
	     (kbd "C-b") "pull-browser"
	     (kbd "f") "fm"
	     (kbd "C-f") "pull-fm"
	     (kbd "c") "term"
	     (kbd "C-c") "pull-term"
	     (kbd "M-c") (concatenate `string "exec " *terminal*)
	     (kbd "d") "discord"
	     (kbd "C-d") "pull-discord"
	     (kbd "v") "raise-mpv"
	     (kbd "C-v") "pull-mpv")

(define-key *root-map* (kbd "e") *programs-keymap*)

(define-key *top-map* (kbd "SunPrint_Screen") "exec scrot -z -e 'mv $f ~/Pictures/Screenshots'")
(define-key *top-map* (kbd "C-SunPrint_Screen") "exec scrot --select -z -e 'mv $f ~/Pictures/Screenshots'")

;; Local Variables:
;; eval: (rainbow-mode)
;; End:
